<?php

namespace app\test;

use app\common\service\order\CouponOrderService;
use app\common\service\pay\PayService;
use app\common\service\pay\wechat\H5;
use app\event\PaySuccess;
use app\model\CouponOrder;
use app\model\PayLog;

class OrderTest
{
    /**
     * 生成已支付的订单
     */
    public function build($product_channel_id = 0)
    {


        //创建订单
        $couponOrder = (new CouponOrderService())
            ->create([
                'product_channel_id' => $product_channel_id != 0 ? $product_channel_id : env('product_channel_id', 1570),
                'serv_type' => PRODUCT_COUPON_SERV,
                'mobile' => 15080206817,
                'account' => 123123
            ]);


        $this->couponOrder = $couponOrder;

        (new PayService($this->couponOrder))->payByCouponOrder(new H5());


        $payLog = PayLog::query()
            ->where('order_id', $this->couponOrder->order_id)
            ->find();

        //支付成功事件
        event(new PaySuccess($payLog));

        $couponOrder = CouponOrder::query()
            ->where('id', $this->couponOrder->id)
            ->find();

        $this->couponOrder = $couponOrder;

        return $couponOrder;
    }

}